package com.acwing.lc.part1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author rkc
 * @date 2022/9/15 9:49
 */
public class LC46全排列 {

    private List<List<Integer>> ans = new ArrayList<>();
    private List<Integer> path = new ArrayList<>();
    private boolean[] st = new boolean[10];

    public List<List<Integer>> permute(int[] nums) {
        dfs(nums);
        return ans;
    }

    private void dfs(int[] nums) {
        if (path.size() == nums.length) {
            ans.add(new ArrayList<>(path));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (!st[i]) {
                st[i] = true;
                path.add(nums[i]);
                dfs(nums);
                path.remove(path.size() - 1);
                st[i] = false;
            }
        }
    }
}
